'use strict';
angular.module('accounting.accountCaptionSelectSingle', ['app.services'])

	.controller('accountCaptionSelectSingleCtrl'
			,['$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title'
			   , f])//控制器结束
    function f($rootScope, $scope, BizData, $uibModalInstance, params, title) {


   		var Model = this;

   		var options = {};
		options.container = Model;
		options.concept = 'AccountCaption';
		options.name = 'dataMaster';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
   		options.creater = '';
   		options.reader = '/accounting/accountCaption/tree/query';
   		options.writer = '';
   		options.deleter = '';
   		options.idColumnDefine = "fID";
   		options.idColumnName = "fID";
   		options.defCols = {fID:{name:"fID",type:"String",label:""},systemCode:{name:"systemCode",type:"String",label:""},billType:{name:"billType",type:"String",label:""},billTypeName:{name:"billTypeName",type:"String",label:""},orderDate:{name:"orderDate",type:"Date",label:""},state:{name:"state",type:"String",label:""},status:{name:"status",type:"String",label:""},captionNo:{name:"captionNo",type:"String",label:""},captionName:{name:"captionName",type:"String",label:""},captionFullID:{name:"captionFullID",type:"String",label:""},captionFullNo:{name:"captionFullNo",type:"String",label:""},captionFullName:{name:"captionFullName",type:"String",label:""},captionType:{name:"captionType",type:"String",label:""},captionTypeLabel:{name:"captionTypeLabel",type:"String",label:""},settleCategory:{name:"settleCategory",type:"String",label:""},settleCategoryLabel:{name:"settleCategoryLabel",type:"String",label:""},dob:{name:"dob",type:"Integer",label:""},dobLabel:{name:"dobLabel",type:"String",label:""},amountL:{name:"amountL",type:"Decimal",label:""},nodeLevel:{name:"nodeLevel",type:"Integer",label:""},nodeKind:{name:"nodeKind",type:"String",label:""},sortNo:{name:"sortNo",type:"String",label:""},fParent:{name:"fParent",type:"String",label:""},comments:{name:"comments",type:"String",label:""},cUsercode:{name:"cUsercode",type:"String",label:""},cUsername:{name:"cUsername",type:"String",label:""},cDatetime:{name:"cDatetime",type:"Datetime",label:""},tUsercode:{name:"tUsercode",type:"String",label:""},tUsername:{name:"tUsername",type:"String",label:""},tDatetime:{name:"tDatetime",type:"Datetime",label:""},eUsercode:{name:"eUsercode",type:"String",label:""},eUsername:{name:"eUsername",type:"String",label:""},eDatetime:{name:"eDatetime",type:"Datetime",label:""},userId:{name:"userId",type:"String",label:""},enterpriseNo:{name:"enterpriseNo",type:"String",label:""},enterpriseName:{name:"enterpriseName",type:"String",label:""},version:{name:"version",type:"Integer",label:""},captionDescribe:{name:"captionDescribe",type:"String",label:""}};
   		options.isTree = true;
   		options.parentRelation = 'fParent';
   		options.nodeKindRelation = 'nodeKind';
   		options.nodeLevelRelation = 'nodeLevel';
   		options.nodeSortRelation = "sortNo";
   		options.rootFilter = 'AccountCaption.fParent is null';
   		options.pathRelation = 'captionFullID';
   		options.directDeleteMode = false;
   		options.limit = -1;
   		options.orderBy = 'sortNo ASC';

   		
   		Model.dataMaster = new BizData(options);
   		//监视对象中的所有变动
//   	Model.dataMaster.deregRows = $scope.$watch('dataAccountCaption.rows',Model.dataMaster.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
   		//////////////////////////////////////////////
	    
	    $scope.tabpanel = 'ZCKM';
	    
	    Model.tabClick = function(billType){
		    $scope.tabpanel = billType;
    		//设置过滤条件
    		Model.dataMaster.filter = "AccountCaption.enterpriseNo='"+ Model.params.id +"'"
    		+ " AND AccountCaption.billType = '"+billType+"'"
    		;
     	
       		Model.dataMaster.refreshData();
		    
	    }

		
		
		//////////////////////对话框使用开始//////////////////////////////////////
		
        //模态窗口打开之后执行的事件
        $uibModalInstance.opened.then(function(){
    		//接收调用对话框的参数
            Model.title = title;  
            Model.params = params;
        	//公司
    		//设置过滤条件
    		Model.dataMaster.filter = "AccountCaption.enterpriseNo='"+ Model.params.id +"'"
    		+ " AND AccountCaption.billType = 'ZCKM'"
    		;
     	
       		Model.dataMaster.refreshData();

        });  
		
        Model.ok = function () {  
	    	//保存成功
	    	//打包数据
	    	var event = {};
	    	var data = [];
	    	var sourceRow = Model.dataMaster.rows[Model.dataMaster.currentIndex];
	    	var row = {};
			//循环行中的列，判断变化点是哪一个
			for(var obj in sourceRow){
				if(obj!='$$hashKey' && obj!='userdata'){
					row[obj] = sourceRow[obj].value;
				}
			}
	    	
	    	data.push(row);
	    	event.data = data;
			$uibModalInstance.close(event);  
	    };  
	    
	    Model.cancel = function () {  
	        $uibModalInstance.dismiss('cancel');  
	    };    
		//////////////////////对话框使用结束//////////////////////////////////////

	    return Model;
	    
	}	
	
